﻿using System.Text.Encodings.Web;
using System.Text.Unicode;
using System.Text;
using MudBlazor.Services;
using BlazorAppDemo.Common;
using MudBlazor;
using BlazorDownloadFile;
using HighlightBlazor;

namespace BlazorAppDemo
{
    public static class ServiceConfigure
    {
        public static void ConfigBlazor(this WebApplicationBuilder builder)
        {
            var services = builder.Services;

            //解决中文编码
            Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-CHS");
            Console.OutputEncoding = Encoding.UTF8;
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            services.AddSingleton(HtmlEncoder.Create(UnicodeRanges.All));

            services.AddHttpClient();

            services.AddMudServices();
            services.AddRazorPages();
            services.AddHighlight();
            services.AddServerSideBlazor()
                    .AddHubOptions(options => options.MaximumReceiveMessageSize = 500 * 1024);
            services.AddRazorComponents(options => options.DetailedErrors = builder.Environment.IsDevelopment())
                    .AddInteractiveServerComponents()
                    .AddHubOptions(options => options.MaximumReceiveMessageSize = 500 * 1024);

            builder.Services.AddBlazorDownloadFile();

            services.AddScoped<MudBreakpointProvider>();
            services.AddScoped<BrowserHelper>();
            services.AddCascadingAuthenticationState();
        }
    }
}
